<?php
/**
 * @author wyl
 * @date 2015-8-6 15:02:01
 */
Yii::import('system.web.widgets.CWidget');
class CButton extends CWidget{
	public $title;
	public $click;
	public $class;
	public $type;
	public $htmlOptions = array();
	
	public function init(){
	    $this->htmlOptions['class'] = $this->class;
	}
	
	public function run(){
	   $this->htmlOptions['id'] = $this->getId();
	   echo CHtml::htmlButton($this->title,$this->htmlOptions);
	   if (!empty($this->click)){
	       $this->bandEvent();
	   }
	}
	
	protected function bandEvent(){
	    $clickCode = CJavaScript::encode($this->click);
	    Yii::app()->clientScript->registerScript(get_class($this).'-'.$this->getId().'-click','
			$("#'.$this->getId().'").on("click",'.$clickCode.');
		');
	}
}